package com.wcx.create.factory.demo1;

import com.wcx.create.factory.demo1.impl.OpreatingAdd;
import com.wcx.create.factory.demo1.impl.OpreatingDiv;
import com.wcx.create.factory.demo1.impl.OpreatingMul;
import com.wcx.create.factory.demo1.impl.OpreatingSub;

/**
 * 项目: design-pattern-githupdemo
 * <p>
 * 功能描述: 简单工厂
 *
 * @author: WuChengXing
 * @create: 2021-01-08 14:11
 **/
public class OpretionFactory {

    public static Operating createOpreation(String opretionStr) {
        Operating operating = null;
        switch (opretionStr) {
            case "+":
                operating = new OpreatingAdd();
                break;
            case "-":
                operating = new OpreatingDiv();
                break;
            case "*":
                operating = new OpreatingMul();
                break;
            case "/":
                operating = new OpreatingSub();
                break;
            default:
                return new Operating() {
                    @Override
                    public Double getResult() {
                        return 0d;
                    }
                };
        }
        return operating;
    }
}
